package com.da.lon.wang.xlg.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.bean.HomeResultBean.HomeItemContentBean;
import com.da.lon.wang.xlg.util.Utils;

import java.util.ArrayList;

public class CategreyAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private ArrayList<HomeItemContentBean> list;
    private Context context;

    public CategreyAdapter(Context context, ArrayList<HomeItemContentBean> cateList) {
        inflater = LayoutInflater.from(context);

        this.list = cateList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.ocoffee_categrey_grid_item,
                    null);
            holder.image = (ImageView) convertView.findViewById(R.id.image);
            holder.text = (TextView) convertView.findViewById(R.id.text);
            Utils.loadImageByGlide(context, list.get(position).getImg_url(), null, holder.image, 0, 0, 1);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        return convertView;
    }

    class ViewHolder {
        ImageView image;
        TextView text;
    }

}
